/*
 * Libgit.h
 *
 *  Created on: 23/10/2013
 *      Author: asc
 */

#ifndef LIBGIT_H_
#define LIBGIT_H_

#include "RepoTemplate/RepoTemplate.h"
#include "utils/utils.h"
#include <string>
#include <libxml++/libxml++.h>
#include <iostream>
#include <exception>
#include <locale>

#include "Libgit.hh"
#include <iostream>
#include <fstream>
using namespace std;


namespace Libgit
{
	/*
	 *
	 * <!-- OLD STYLE --!>
	 * git log --date=iso --pretty=format:"
		<logentry revision='%h' parent='%p'>%n
			<author email='%ae'>%an</author>%n
			<date>%ad</date>%n
			<msg>%n%s%n</msg>%n
		</logentry>"
	   | sed
			-e '1i<?xml version="1.0" encoding="utf-8"?><logs>'
			-e '$a</logs>'
			-e '/<msg>/a <![CDATA['
			-e '/<\/msg>/i ]]>' > file.xml

	 * <!-- NEW STYLE --!>
	 * git log --date=iso --pretty=format:"
		<logentry>
			<revision>%h</revision>%n
			<parent>%p</parent>%n
			<author>%an</author>%n
			<email>%ae</email>
			<date>%ad</date>%n
			<msg>%s</msg>%n
		</logentry>"\
		| sed -e '1i<?xml version="1.0" encoding="utf-8"?><logs>' -e '$a</logs>' > file.xml
	 *
	 */
	enum keys_git{log, logentry, revision, parent, author, email,date, msg};
	map<string,keys_git> resolv_key_git =
	{
			{"log"				,log},
			{"logentry"			,logentry},
			{"revision"			,revision},
			{"author"			,author},
			{"email"			,email},
			{"parent"			,parent},
			{"date"				,date},
			{"msg"				,msg}
	};

	class Libgit: public RepoTemplate
	{
		public:
			Libgit();
			Libgit(string file2parse);
			~Libgit();
			void read();
		private:
			void parseSubTree(xmlpp::TextReader &reader);
			void parse();
			void parseGrammar();
	};

} /* namespace libgit */
#endif /* LIBGIT_H_ */
